import { Controller, Post, Body } from '@nestjs/common';
import { AuthService } from './auth.service';
import { Public } from '@/common/decorator';
import { LonginDto } from './dto/login.dto';
import { BusinessException } from '@/common/excepetion';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Public()
  @Post('login')
  async login(@Body() loginData: LonginDto) {
    const user = await this.authService.validateUser(
      loginData.account,
      loginData.password,
    );

    if (!user) {
      throw new BusinessException({ msg: '用户验证失败' });
    }

    return this.authService.login(user);
  }
}
